#include "Matrice.h"
void Matrice::citire()
{
    int n,m;
    cout<<"Introduceti nr de linii: "; cin>>n;
    cout<<"Introduceti nr de coloane:"; cin>>m;
    this->n=n;
    this->m=m;
    for (int i=0;i<n;i++)
    for (int j=0;j<m;j++)
    {
        cout<<"Introduceti el de pe pozitia ["<<i<<","<<j<<"] :"; cin>>this->a[i][j];
    }
}
int Matrice::getLinii()
{
    return this->n;
}
int Matrice::getColoane()
{
    return this->m;
}
void Matrice::setLinii(int n)
{
    this->n=n;
}
void Matrice::setColoane(int m)
{
    this->m=m;
}
int Matrice::getElement(int i, int j)
{
    return this->a[i][j];
}
void Matrice::setElement(int x, int i, int j)
{
    this->a[i][j]=x;
}
void Matrice::afisare()
{
    int n=getLinii(), m=getColoane();
    for (int i=0;i<n;i++)
    {
    for (int j=0;j<m;j++) cout<<this->getElement(i,j)<<" ";
    cout<<endl;
    }
}
Matrice Matrice::init ()
{
    Matrice x;
    int n=getLinii(), m=getColoane();
    x.setLinii(n);
    x.setColoane(m);
    for (int i=0;i<n;i++)
    for (int j=0;j<m;j++)
    {
        x.setElement(this->getElement(i,j),i,j);
    }
    return x;
}
int Matrice::getElement(int k)
{
    int x=0;
    int n=this->getLinii(), m=this->getColoane();
    for (int i=0;i<n*m-1;i++)
    for (int j=i+1;j<n*m;j++)
    {
    x++;
    if (k==x) return this->a[i][j];
    }
}
void Matrice::ordonare()
{
   int n=this->getLinii(), m=this->getColoane(),lini,coli,linj,colj,aux;
   for (int i=0;i<n*m-1;i++)
   {
    lini=i/n;
    coli=i%n;
   for (int j=i+1;j<n*m;j++)
   {
    linj=j/n;
    colj=j%n;
    if(this->getElement(lini,coli)>this->getElement(linj,colj))
    {
        aux=this->a[lini][coli];
        this->a[lini][coli]=this->a[linj][colj];
        this->a[linj][colj]=aux;
    }
   }
   }
}
Matrice Matrice::operator+(int k)
{
    int n=this->getLinii(), m=this->getColoane();
    Matrice x;
    x.setLinii(n);
    x.setColoane(m);
    for (int i=0;i<n;i++)
    for (int j=0;j<m;j++)
    {
        x.setElement(this->a[i][j]+k,i,j);
    }
    return x;
}
Matrice Matrice::operator-(int k)
{
    int n=this->getLinii(), m=this->getColoane();
    Matrice x;
    x.setLinii(n);
    x.setColoane(m);
    for (int i=0;i<n;i++)
    for (int j=0;j<m;j++)
    {
        x.setElement(this->a[i][j]-k,i,j);
    }
    return x;
}
Matrice Matrice::operator*(int k)
{
    int n=this->getLinii(), m=this->getColoane();
    Matrice x;
    x.setLinii(n);
    x.setColoane(m);
    for (int i=0;i<n;i++)
    for (int j=0;j<m;j++)
    {
        x.setElement(this->a[i][j]*k,i,j);
    }
    return x;
}
Matrice Matrice::operator/(int k)
{
    int n=this->getLinii(), m=this->getColoane();
    Matrice x;
    x.setLinii(n);
    x.setColoane(m);
    for (int i=0;i<n;i++)
    for (int j=0;j<m;j++)
    {
        x.setElement(this->a[i][j]/k,i,j);
    }
    return x;
}
